﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Peak.Core;

namespace Peak.Web.Controllers.Models
{
  public class SprintModel : ModelBase
  {
    public int SprintId { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public DateTime Start { get; set; }
    public DateTime End { get; set; }
    public SprintStatus Status { get; set; }
    public double RealVelocity { get; private set; }
    public double EstimatedVelocity { get; set; } 
    public int Days{ get; private set; }
    public TimeSpan RemainingEffort { get; private set; }


    public SprintModel() : base(()=>new SprintModelValidator())
    {      
    }

    public SprintModel(Sprint sprint) : base(() => new SprintModelValidator())
    {
      SprintId = sprint.Id;
      Name = sprint.Name;
      Description = sprint.Description;
      Start = sprint.StartDate;
      End = sprint.EndDate;
      Status = sprint.Status;
      RemainingEffort = sprint.RemainingEffort;
      EstimatedVelocity = sprint.EstimatedVelocity;
      RealVelocity = sprint.RealVelocity;
      for (DateTime date = Start; date <= End; date = date.AddDays(1))
      {
        if (sprint.Project.Calendar.IsWorkingDay(date))
          Days++;
      }
    }

    public void Update(Sprint sprint)
    {      
      sprint.Name = Name;
      sprint.Description = Description;
      sprint.StartDate = Start;
      sprint.EndDate = End;
      sprint.Status = Status;      
    }
  }
}
